<?php


namespace App\Controller;


use News\Model\NewsDetailModel;
use News\Model\NewsModel;

class NewsController extends AppBaseController
{
    public function lists()
    {
        $page = I("page", 1, 'intval');

        $NewsModel = new NewsModel();
        $lists = $NewsModel->field('id,create_time,title,description')->where(['category' => 3, 'status' => 1])->order('create_time DESC')->page($page, 5)->select();
        foreach ($lists as &$val) {
            $val['create_time'] = date("Y-m-d", $val['create_time']);

            //$val['description'] = trim(htmlspecialchars(op_t($val['description'])));
//            preg_replace("/(\s|\&nbsp\;|　|\xc2\xa0)/", " ", strip_tags($val['description']));
//            preg_replace("/(\s|\&amp\;|　|\xc2\xa0)/", " ", strip_tags($val['description']));
            $val['description'] = preg_replace("/&#?[a-z0-9]+;/i","",$val['description']);
        }
        $this->jsuccess($lists);
    }

    public function detail($id)
    {
        $NewsDetail = new NewsDetailModel();
        $detail = $NewsDetail->where(['news_id' => $id])->getField("content");
        $detail = op_h($detail);
        $this->jsuccess($detail);
    }

    public function aboutUs()
    {
        $NewsDetail = new NewsDetailModel();
        $data = $NewsDetail->where(['news_id' => 13])->getField("content");
        $this->jsuccess($data);
    }
}